using System;
using System.Net;
using System.Net.Mail;
using System.IO;
using System.Text;
using System.Collections.Specialized;

namespace sendmailex
{
	class MainClass
	{
		public static void Main (string[] args)
		{
			NameValueCollection paramsters = Silmoon.SmString.AnalyzeNameValue(args, ":", "-");
			
			string host = paramsters["-host"];
			string username = paramsters["-username"];
			string sender = paramsters["-sender"];
			string tomode = paramsters["-tomode"];
			string mfrom = paramsters["-from"];
			string to = paramsters["-to"];
			string password = paramsters["-password"];
			string contentmode = paramsters["-contentmode"];
			string content = paramsters["-content"];
			string subject = paramsters["-subject"];
			bool nologo = false;
			if(paramsters["nologo"] == null) nologo = true;
			
			if(string.IsNullOrEmpty(sender)) mfrom = username;
			if(string.IsNullOrEmpty(mfrom)) mfrom = username;
			if(string.IsNullOrEmpty(mfrom)) mfrom = sender;
			if(string.IsNullOrEmpty(sender)) sender = mfrom;
			
			if(!nologo) Console.WriteLine ("[Silmoon Mail Sender]");
			Console.WriteLine ("[SENDMAILEX] " + to + " Sending...");
			SmtpClient mailClient = new SmtpClient(host);
			mailClient.Credentials = new NetworkCredential(username, password);
			MailMessage message = new MailMessage(mfrom, to);
			message.Body = content;
			message.Sender = new MailAddress(sender);
			message.Subject = subject;
			mailClient.Send(message);
			Console.WriteLine ("[SENDMAILEX] Send successed.");
		}
	}
}